package model

import (
	"blog/app/common"
	"blog/app/utils"
	"time"
)

type Visit struct {
	ID        uint64     `json:"id"`
	IP        string    `json:"ip"`
	ArticleID uint64     `json:"article_id"`
	CreateAt  time.Time `json:"create_at"`
}

// visit 增加一条记录
func (v *Visit) InsertOne() bool {
	now := time.Now()
	sql := "insert into visit (ip,article_id,create_at) value(?,?,?)"
	rs, err := common.DB.Exec(sql, v.IP, v.ArticleID, now)
	if utils.CheckErr(err) {
		return false
	}
	_, err = rs.LastInsertId()
	if utils.CheckErr(err) {
		return false
	}
	return true
}
